IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('UserInsert') AND sysstat & 0xf = 4)
    DROP PROCEDURE [UserInsert]
GO
CREATE PROCEDURE [UserInsert]
(
    @UserId int = null output,
    @UserName nvarchar(100),
    @Password nvarchar(500)
)
AS
BEGIN
	SET NOCOUNT ON
	INSERT INTO [user](
        [user_name],
        [password],
        [create_date]
	)
	VALUES(
        @UserName,
        @Password,
        GetDate()
	)
	SELECT @UserId = SCOPE_IDENTITY()
END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('UserUpdate') AND sysstat & 0xf = 4)
    DROP PROCEDURE [UserUpdate]
GO
CREATE PROCEDURE [UserUpdate]
(
	@UserId int,
    @UserName nvarchar,
    @Password nvarchar,
    @CreateDate datetime,
    @UpdateDate datetime
)
AS
BEGIN
	
	UPDATE [user]
	SET
        [user_name]=@UserName,
        [password]=@Password,
        [create_date]=@CreateDate,
        [update_date]=@UpdateDate
	WHERE
		[user_id] = @UserId

END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('UserDelete') AND sysstat & 0xf = 4)
    DROP PROCEDURE [UserDelete]
GO
CREATE PROCEDURE [UserDelete]
(
	@UserId int	
)
AS
BEGIN
	
	DELETE
	FROM [user]
    WHERE
		[user_id] = @UserId
END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('UserSelectOne') AND sysstat & 0xf = 4)
    DROP PROCEDURE [UserSelectOne]
GO
CREATE PROCEDURE [UserSelectOne]
(
	@UserId int
)
AS
BEGIN
	SET NOCOUNT ON	
	SELECT
		*
	FROM [user] (NOLOCK)
	WHERE
		([user_id] = @UserId)

END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('UserSelectAll') AND sysstat & 0xf = 4)
    DROP PROCEDURE [UserSelectAll]
GO

CREATE PROCEDURE [UserSelectAll]
AS
BEGIN

	SET NOCOUNT ON
	SELECT
		user_id as UserId,
		user_name as UserName,
		Password
	FROM [user] (NOLOCK)

END
GO